var _tools = require("../../../utils/tools.js"), _tools2 = _interopRequireDefault(_tools);

function _interopRequireDefault(t) {
    return t && t.__esModule ? t : {
        default: t
    };
}

var that, app = getApp();

function compareV(t, e) {
    if (t && e) {
        for (var a = t.split("."), o = e.split("."), i = Math.min(a.length, o.length), n = 0, s = 0; n < i && 0 == (s = parseInt(a[n]) - parseInt(o[n])); ) n++;
        return 0 <= (s = 0 != s ? s : a.length - o.length);
    }
    return !1;
}

Page({
    data: {
        pageName: "pdd",
        activeIndex: 0,
        page: 1,
        isover: !1,
        pdd_keyword: "",
        top_h: 62,
        m_height: 50
    },
    onLoad: function(t) {
        that = this, that.setData({
            top_h: app.globalData.nav_height ? app.globalData.nav_height : 62
        });
    },
    showInput: function() {
        wx.navigateTo({
            url: "/bh_rising/pages/search/search"
        });
    },
    tabClick: function(t) {
        var e = t.currentTarget.dataset.index;
        this.setData({
            isover: !1,
            page: 1,
            activeIndex: e,
            pdd_keyword: ""
        }), that.loadGoods();
    },
    click_nav_det: function(t) {
        var e = t.currentTarget.dataset.goods_id, a = t.currentTarget.dataset.search_id;
        wx.navigateTo({
            url: "/bh_rising/pages/pdd_details/pdd_details?goods_id=" + e + "&search_id=" + a
        });
    },
    loadGoods: function() {
        var t = this.data.category[this.data.activeIndex].opt_id, e = {
            action: "goods",
            contr: "pdd",
            token: wx.getStorageSync("token"),
            page: that.data.page,
            opt_id: t,
            pdd_keyword: this.data.pdd_keyword
        };
        _tools2.default.request(e, function(t) {
            var e = t.info.pddGoodsList;
            1 < that.data.page && (e = that.data.pddGoodsList.concat(e)), that.setData({
                pddGoodsList: e
            }), t.info.pddGoodsList < 10 && that.setData({
                isover: !0
            });
        });
    },
    onReachBottom: function() {
        this.data.isover || (this.data.page++, this.loadGoods());
    },
    onReady: function() {
        var t = {
            action: "category",
            contr: "pdd",
            token: wx.getStorageSync("token")
        };
        _tools2.default.request(t, function(t) {
            that.setData(t.info), t.info.category && that.loadGoods(), wx.createSelectorQuery().select("#global-navbar").boundingClientRect(function(t) {
                that.setData({
                    m_height: t.height
                });
            }).exec();
        });
    },
    hideInviteRed: function() {
        this.setData({
            invite_red_show: !1
        });
    },
    showInviteRed: function() {
        this.setData({
            invite_red_show: !0
        });
    },
    hideSell: function() {
        this.setData({
            showSell: !1
        });
    },
    onSellEgg: function() {
        this.setData({
            showSell: !0
        });
    },
    onShow: function() {},
    gotoTelephoneBill: function() {
        wx.navigateTo({
            url: "/bh_farm/pages/exchange/exchange"
        });
    },
    navigatorSwitch: function(t) {
        var e = t.detail.pageName;
        if (e != this.data.pageName) {
            if ("index" == e) var a = "/bh_farm/pages/index/index"; else if ("recruit" == e) a = "/bh_farm/pages/recruit/recruit"; else if ("mine" == e) a = "/bh_farm/pages/my/my"; else if ("db" == e) a = "/bh_farm/pages/treasure/treasure";
            wx.redirectTo({
                url: a
            });
        }
    },
    onShareAppMessage: function() {
        return {
            title: this.data.share.text,
            imageUrl: this.data.share.images,
            path: "bh_rising/pages/index/index?parent_id=" + this.data.share.member_id
        };
    },
    getUserInfo: function(t) {
        if ("getUserInfo:ok" == t.detail.errMsg) {
            var e = {
                action: "register",
                contr: "home",
                token: wx.getStorageSync("token"),
                encryptedData: t.detail.encryptedData,
                iv: t.detail.iv
            };
            _tools2.default.request(e, function(t) {
                that.onReady(), that.showInviteRed();
            });
        }
    }
});